<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="模型id" prop="modelId">
        <el-select v-model="queryParams.modelId" placeholder="请选择模型id" clearable>
          <el-option
              v-for="dict in valid"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" style="width: 308px">
        <el-date-picker
            v-model="daterangeCreateTime"
            value-format="YYYY-MM-DD"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>-->

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['ba:baModel3Detail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="Edit"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['ba:baModel3Detail:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['ba:baModel3Detail:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['ba:baModel3Detail:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baModel3DetailList" @selection-change="handleSelectionChange" stripe>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="流水号" align="center" prop="id" v-if="false"/>
      <el-table-column label="模型id" align="center" prop="modelId" v-if="false">
        <template #default="scope">
          <dict-tag :options="valid" :value="scope.row.modelId"/>
        </template>
      </el-table-column>
      <el-table-column label="分析id" align="center" prop="hisId" v-if="false"/>
      <el-table-column label="底部向上的长度(m)" align="center" prop="tspan" width="140px"/>
      <el-table-column label="管道长度方向上的位移(m)" align="center" prop="xDisp" v-if="false"/>
      <el-table-column label="管道横截面y方向的位移(m)" align="center" prop="yDisp" v-if="false"/>
      <el-table-column label="管道横截面z方向的位移(m)" align="center" prop="zDisp" v-if="false"/>
      <el-table-column label="管道横截面y和z方向的总位移(m)-挠度" align="center" prop="yzDisp" />
      <el-table-column label="角度(偏向y或z)" align="center" prop="angle" v-if="false"/>
      <el-table-column label="L方向微应变(ue)" align="center" prop="strainL" v-if="false"/>
      <el-table-column label="U方向微应变(ue)" align="center" prop="strainU" v-if="false"/>
      <el-table-column label="R方向微应变(ue)" align="center" prop="strainR" v-if="false"/>
      <el-table-column label="轴向应力(MPa)" align="center" prop="stressT" />
      <el-table-column label="弯曲应力(MPa)" align="center" prop="stressBMax" />
      <el-table-column label="轴向附加应力(MPa)" align="center" prop="stressMax" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['ba:baModel3Detail:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['ba:baModel3Detail:remove']">删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改崩岸模型3计算明细对话框 -->
    <el-dialog :title="title" v-model="open" width="600px" append-to-body>
      <el-form ref="baModel3DetailRef" :model="form" :rules="rules" label-width="200px">
        <el-form-item label="模型id" prop="modelId">
          <el-select v-model="form.modelId" placeholder="请选择模型id">
            <el-option
                v-for="dict in valid"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分析id" prop="hisId">
          <el-input v-model="form.hisId" placeholder="请输入分析id" />
        </el-form-item>
        <el-form-item label="底部向上的长度(m)" prop="tspan">
          <el-input v-model="form.tspan" placeholder="请输入底部向上的长度(m)" />
        </el-form-item>
        <el-form-item label="管道长度方向上的位移(m)" prop="xDisp">
          <el-input v-model="form.xDisp" placeholder="请输入管道长度方向上的位移(m)" />
        </el-form-item>
        <el-form-item label="管道横截面y方向的位移(m)" prop="yDisp">
          <el-input v-model="form.yDisp" placeholder="请输入管道横截面y方向的位移(m)" />
        </el-form-item>
        <el-form-item label="管道横截面z方向的位移(m)" prop="zDisp">
          <el-input v-model="form.zDisp" placeholder="请输入管道横截面z方向的位移(m)" />
        </el-form-item>
        <el-form-item label="管道横截面y和z方向的总位移(m)-挠度" prop="yzDisp">
          <el-input v-model="form.yzDisp" placeholder="请输入管道横截面y和z方向的总位移(m)-挠度" />
        </el-form-item>
        <el-form-item label="角度(偏向y或z)" prop="angle">
          <el-input v-model="form.angle" placeholder="请输入角度(偏向y或z)" />
        </el-form-item>
        <el-form-item label="L方向微应变(ue)" prop="strainL">
          <el-input v-model="form.strainL" placeholder="请输入L方向微应变(ue)" />
        </el-form-item>
        <el-form-item label="U方向微应变(ue)" prop="strainU">
          <el-input v-model="form.strainU" placeholder="请输入U方向微应变(ue)" />
        </el-form-item>
        <el-form-item label="R方向微应变(ue)" prop="strainR">
          <el-input v-model="form.strainR" placeholder="请输入R方向微应变(ue)" />
        </el-form-item>
        <el-form-item label="轴向应力(MPa)" prop="stressT">
          <el-input v-model="form.stressT" placeholder="请输入轴向应力(MPa)" />
        </el-form-item>
        <el-form-item label="弯曲应力(MPa)" prop="stressBMax">
          <el-input v-model="form.stressBMax" placeholder="请输入弯曲应力(MPa)" />
        </el-form-item>
        <el-form-item label="轴向附加应力(MPa)" prop="stressMax">
          <el-input v-model="form.stressMax" placeholder="请输入轴向附加应力(MPa)" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="BaModel3Detail">
import { listBaModel3Detail, getBaModel3Detail, delBaModel3Detail, addBaModel3Detail, updateBaModel3Detail } from "@/api/ba/baModel3Detail";

const { proxy } = getCurrentInstance();
const { valid } = proxy.useDict('valid');

const baModel3DetailList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const daterangeCreateTime = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    hisId: null,
    modelId: null,
    createTime: null,
  },
  rules: {
    modelId: [
      { required: true, message: "模型id不能为空", trigger: "change" }
    ],
    hisId: [
      { required: true, message: "分析id不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

const props = defineProps({
  model3His: {
    type: Object,
    required: true,
    default: {
      id: -1,
      fiberNum: undefined,
      hisId: undefined,
      modelId: undefined
    }
  }
})

/** 查询崩岸模型3计算明细列表 */
function getList() {
  loading.value = true;
  /*queryParams.value.params = {};
  if (null != daterangeCreateTime && '' != daterangeCreateTime) {
    queryParams.value.params["beginCreateTime"] = daterangeCreateTime.value[0];
    queryParams.value.params["endCreateTime"] = daterangeCreateTime.value[1];
  }*/
  console.log(`detail--queryParams.value:${JSON.stringify(queryParams.value)}`)
  listBaModel3Detail(queryParams.value).then(response => {
    baModel3DetailList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    modelId: null,
    hisId: null,
    tspan: null,
    xDisp: null,
    yDisp: null,
    zDisp: null,
    yzDisp: null,
    angle: null,
    strainL: null,
    strainU: null,
    strainR: null,
    stressT: null,
    stressBMax: null,
    stressMax: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null
  };
  proxy.resetForm("baModel3DetailRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  daterangeCreateTime.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加崩岸模型3计算明细";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getBaModel3Detail(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改崩岸模型3计算明细";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["baModel3DetailRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateBaModel3Detail(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addBaModel3Detail(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除崩岸模型3计算明细编号为"' + _ids + '"的数据项？').then(function() {
    return delBaModel3Detail(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('ba/baModel3Detail/export', {
    ...queryParams.value
  }, `baModel3Detail_${new Date().getTime()}.xlsx`)
}

// getList();

function init(){
  queryParams.value.hisId = props.model3His.id
  queryParams.value.modelId = props.model3His.modelId

  getList()
}

defineExpose({
  init
})
</script>
